*/
+#include <algorithm> // for stable_sort
#include <cstdio> // for sprintf
-#include <cstdlib> // for qsort
#include <cstring> // for memset, strncpy
#include <QDateTime> // for QDateTime
because, sadly, quicksort can be O(n^2) on presorted elements.)
*/
-
-int DuplicateFilter::compare(const void* a, const void* b)
-{
- const wpt_ptr* wa = (wpt_ptr*)a;
- const wpt_ptr* wb = (wpt_ptr*)b;
-
- if (wa->wpt->gc_data->exported < wb->wpt->gc_data->exported) {
- return 1;
- } else if (wa->wpt->gc_data->exported > wb->wpt->gc_data->exported) {
- return -1;
- }
-
- /* If the exported dates are the same, sort by index. */
- if (wa->index < wb->index) {
- return -1;
- } else if (wa->index > wb->index) {
- return 1;
- }
-
- /* If index and date are the same, it's the same element. */
- return 0;
-
-}
-
void DuplicateFilter::process()
{
btree_node* btmp = nullptr;
} dupe;
Waypoint* delwpt = nullptr;
- int ct = waypt_count();
-
- auto* htable = (wpt_ptr*) xmalloc(ct * sizeof(wpt_ptr));
- wpt_ptr* bh = htable;
+ auto htable = *global_waypoint_list;
- int i = 0;
- foreach (Waypoint* waypointp, *global_waypoint_list) {
- bh->wpt = waypointp;
- bh->index = i;
- i ++;
- bh ++;
- }
- qsort(htable, ct, sizeof(*htable), compare);
+ auto compare_lambda = [](const Waypoint* wa, const Waypoint* wb)->bool {
+ return wa->gc_data->exported > wb->gc_data->exported;
+ };
+ std::stable_sort(htable.begin(), htable.end(), compare_lambda);
- for (i=0; i<ct; i++) {
- auto* waypointp = htable[i].wpt;
+ for (Waypoint* waypointp : htable) {
memset(&dupe, '\0', sizeof(dupe));
delete delwpt;
- xfree(htable);
if (sup_tree) {
free_tree(sup_tree);
}
static btree_node* addnode(btree_node* tree, btree_node* newnode, btree_node** oldnode);
void free_tree(btree_node* tree);
- struct wpt_ptr {
- Waypoint* wpt;
- int index;
- };
-
- static int compare(const void* a, const void* b);
-
};
#endif
#endif // DUPLICATE_H_INCLUDED_
#include "defs.h"
#if CSVFMTS_ENABLED
+#include <algorithm> // for sort
#include <cctype> // for toupper
#include <cmath> // for fabs, floor
#include <cstdio> // for NULL, snprintf, sscanf
#include <cstdint>
-#include <cstdlib> // for atoi, abs, qsort
+#include <cstdlib> // for atoi, abs
#include <cstring> // for memset, strstr, strcat, strchr, strlen, strcmp, strcpy, strncpy
#include <ctime> // for gmtime, localtime, strftime
}
-static int
-sort_waypt_cb(const void* a, const void* b)
-{
- const Waypoint* wa = *(Waypoint**)a;
- const Waypoint* wb = *(Waypoint**)b;
- return wa->shortname.compare(wb->shortname, Qt::CaseInsensitive);
-}
-
-
/* common route and track pre-work */
static void
if (waypoints > 0) {
wpt_a_ct = 0;
- wpt_a = (const Waypoint**)xcalloc(waypoints, sizeof(*wpt_a));
+ wpt_a = new const Waypoint*[waypoints]{};
waypt_disp_all(enum_waypt_cb);
route_disp_all(nullptr, nullptr, enum_waypt_cb);
- qsort(wpt_a, waypoints, sizeof(*wpt_a), sort_waypt_cb);
+ auto sort_waypt_lambda = [](const Waypoint* wa, const Waypoint* wb)->bool {
+ return wa->shortname.compare(wb->shortname, Qt::CaseInsensitive) < 0;
+ };
+ std::sort(wpt_a, wpt_a + waypoints, sort_waypt_lambda);
*fout << QString::asprintf("Header\t%s\r\n\r\n", headers[waypt_header]);
for (int i = 0; i < waypoints; i++) {
- const Waypoint* wpt = wpt_a[i];
- write_waypt(wpt);
+ write_waypt(wpt_a[i]);
}
- xfree(wpt_a);
+ delete[] wpt_a;
route_idx = 0;
route_info = (info_t*) xcalloc(route_count(), sizeof(info_t));
--- /dev/null
+No,Latitude,Longitude,Name,Exported
+1,40.0,-105.1,"zero",2015/06/24 00:00:00
+1,40.0,-105.2,"one",2015/06/25 00:00:01
+1,40.0,-105.2,"two",2015/06/25 00:00:00
+1,40.0,-105.1,"three",2015/06/24 00:00:01
--- /dev/null
+No,Latitude,Longitude,Name,Exported\r
+1,40.000000,-105.200000,"one","2015/06/25 00:00:01"\r
+2,40.000000,-105.100000,"three","2015/06/24 00:00:01"\r
--- /dev/null
+No,Latitude,Longitude,Name,Exported
+1,40.0,-105.1,"zero",2015/06/24 00:00:02
+1,40.0,-105.2,"one",2015/06/25 00:00:01
+1,40.0,-105.2,"two",2015/06/25 00:00:02
+1,40.0,-105.1,"three",2015/06/24 00:00:01
--- /dev/null
+No,Latitude,Longitude,Name,Exported\r
+1,40.000000,-105.100000,"zero","2015/06/24 00:00:02"\r
+2,40.000000,-105.200000,"two","2015/06/25 00:00:02"\r
2008/08/20: added "relative" option, (Carsten Allefeld, carsten.allefeld@googlemail.com)
*/
-#include <cstdlib> // for qsort, strtol
+#include <algorithm> // for sort
+#include <cstdlib> // for strtol
#include <utility> // for swap
#include <QDateTime> // for QDateTime
const auto* xte_b = static_cast<const struct xte*>(b);
if (HUGEVAL == xte_a->distance) {
+ if (HUGEVAL == xte_b->distance) {
+ return 0;
+ }
return -1;
}
/* sort XTE array, lowest XTE last */
- qsort(xte_recs, xte_count, sizeof(struct xte), compare_xte);
+ auto compare_xte_lambda = [](const xte& a, const xte& b)->bool {
+ return compare_xte(&a, &b) < 0;
+ };
+ std::sort(xte_recs, xte_recs + xte_count, compare_xte_lambda);
+
for (i = 0; i < xte_count; i++) {
xte_recs[i].intermed->xte_rec = xte_recs+i;
gpsbabel -i geo -f ${REFERENCE}/geocaching.loc -f ${REFERENCE}/geocaching.loc -x duplicate,shortname \
-o csv -F ${TMPDIR}/filterdupe.csv2
sort_and_compare ${TMPDIR}/filterdupe.csv1 ${TMPDIR}/filterdupe.csv2
+
+gpsbabel -i unicsv,utc -f ${REFERENCE}/duplicate_exported_1.csv -x duplicate,location -o unicsv,utc -F ${TMPDIR}/duplicate_exported_1~csv.csv
+compare ${REFERENCE}/duplicate_exported_1~csv.csv ${TMPDIR}/duplicate_exported_1~csv.csv
+gpsbabel -i unicsv,utc -f ${REFERENCE}/duplicate_exported_2.csv -x duplicate,location -o unicsv,utc -F ${TMPDIR}/duplicate_exported_2~csv.csv
+compare ${REFERENCE}/duplicate_exported_2~csv.csv ${TMPDIR}/duplicate_exported_2~csv.csv